﻿#region
/*******************************************************************************
** File Name:		    SupplierService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class SupplierService : ISupplierService
    {
		 ISupplier supplier = new SupplierRepository();
		 
		 #region  Auto Generation
		 

		public void UpdateBySupplierID (SupplierModel model)
		{
			ESupplier entity = ConvertModelToEntity(model);

            supplier.UpdateBySupplierID(entity);

		}

		public void DeleteBySupplierID (System.Int64 supplierID)
		{
		
            supplier.DeleteBySupplierID(supplierID);

		}
		 
        public SupplierModel GetBySupplierID (System.Int64 supplierID)
        {
        
			ESupplier entity = supplier.GetBySupplierID(supplierID);
			
            SupplierModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<SupplierModel> GetAll ()
		{
			IList<ESupplier> entity = supplier.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<SupplierModel> list = new List<SupplierModel>();

            foreach (var item in entity)
            {
                SupplierModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private SupplierModel ConvertEntityToModel(ESupplier entity)
		{
			if (entity == null)
            {
                return null;
            }
			SupplierModel model = new SupplierModel();
                        model.SupplierID = entity.SupplierID;
                        model.Code = entity.Code;
                        model.Name = entity.Name;
                        model.ChsSpell = entity.ChsSpell;
                        model.Note = entity.Note;
                        model.ContractTel = entity.ContractTel;
                        model.Mobile = entity.Mobile;
                        model.ContactName = entity.ContactName;
                        model.Address = entity.Address;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTiem = entity.UpdateTiem;
                        return model;
		}
		
		private ESupplier ConvertModelToEntity(SupplierModel model)
		{
			if (model == null)
            {
                return null;
            }
			ESupplier entity = new ESupplier();
                        entity.SupplierID = model.SupplierID;
                        entity.Code = model.Code;
                        entity.Name = model.Name;
                        entity.ChsSpell = model.ChsSpell;
                        entity.Note = model.Note;
                        entity.ContractTel = model.ContractTel;
                        entity.Mobile = model.Mobile;
                        entity.ContactName = model.ContactName;
                        entity.Address = model.Address;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTiem = model.UpdateTiem;
                        return entity;
		}
		
		
		
		#endregion
    }
}